﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    HyperLink[] b = null;
    int Max = 30;
    protected void Menu()
    {
        b[0] = linkquanlytaikhoan;
        b[1] = nhaplieutudong;
        b[2] = linkCacdanhmuc;
        b[3] = linktintucthongbao;
        b[4] = linkTaoMoiCSD;
        b[5] = linkCapNhatCSD;
        b[6] = linkTruyvandoanvien;
        b[7] = linkrenluyendoanvien;
        b[8] = linkketquarenluyen;
        b[9] = linkdsgiaithe;
        b[10] = linkthemmoidoanvien;
        b[11] = linkquanlydoanvien;
        b[12] = linkdanhsachdoanvientrungthanh;
        b[13] = linkdanhsachdoanviendanhdu;
        b[14] = linkdanhsachgioithieudang;
        b[15] = linkdoanvienbixoa;
        b[16] = linkdoanviendubi;
        b[17] = linkdoanviencct;
        b[18] = linkdoanvienkhaitru;
        b[19] = linkdscanbodoan;
        b[20] = phuluc2a;
        b[21] = phuluc2b;
        b[22] = phuluc2c;
        b[23] = phuluc2d;
        b[24] = phuluc2e;
        b[25] = phuluc2g;
        b[26] = phuluc2h;
        b[27] = thongketuybien;
        b[28] = linkchuongtrinhdaotao;
        b[29] = linkDangKyLopHoc;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SecurityLib.Sec_AES _ps = new SecurityLib.Sec_AES();
        //phan tai khoan
        linkquanlytaikhoan.NavigateUrl = PageURL.local + "DanhMuc/AcountManager.aspx?id=" + _ps.Encrypt("1","gold",128) + "&subid=" + _ps.Encrypt("1","gold",128);
        nhaplieutudong.NavigateUrl = PageURL.local + "DanhMuc/NhaplieuExcel.aspx?id=" + _ps.Encrypt("1", "gold", 128) + "&subid=" + _ps.Encrypt("2", "gold", 128);

        //quan ly danh muc
        linkCacdanhmuc.NavigateUrl = PageURL.local + "DanhMuc/QuanLyDanhMuc.aspx?id=" + _ps.Encrypt("2","gold",128) + "&subid=" + _ps.Encrypt("1","gold",128);
        linktintucthongbao.NavigateUrl = PageURL.local + "News/QuanLyTinTuc.aspx?id=" + _ps.Encrypt("2", "gold", 128) + "&subid=" + _ps.Encrypt("2", "gold", 128);
        //quan ly co so doan
        linkTaoMoiCSD.NavigateUrl = PageURL.local + "DanhMuc/ThemCoSoDoan.aspx?id=" + _ps.Encrypt("3","gold",128) + "&subid=" + _ps.Encrypt("1","gold",128);
        linkCapNhatCSD.NavigateUrl = PageURL.local + "DanhMuc/UpdateCoSoDoan.aspx?id=" + _ps.Encrypt("3","gold",128) + "&subid=" + _ps.Encrypt("2","gold",128);
        linkTruyvandoanvien.NavigateUrl = PageURL.local + "DanhMuc/TruyVanDoanVien.aspx?id=" + _ps.Encrypt("3", "gold", 128) + "&subid=" + _ps.Encrypt("3", "gold", 128);
        linkrenluyendoanvien.NavigateUrl = PageURL.local + "DanhMuc/RenLuyenDoanVien.aspx?id=" + _ps.Encrypt("3", "gold", 128) + "&subid=" + _ps.Encrypt("4", "gold", 128);
        linkketquarenluyen.NavigateUrl = PageURL.local + "DanhMuc/DanhSachDoanVienDangKyRenLuyen.aspx?id=" + _ps.Encrypt("3", "gold", 128) + "&subid=" + _ps.Encrypt("5", "gold", 128);
        linkdsgiaithe.NavigateUrl = PageURL.local + "DanhMuc/DanhSachDonViGiaiThe.aspx?id=" + _ps.Encrypt("3", "gold", 128) + "&subid=" + _ps.Encrypt("5", "gold", 128);
        //quan ly doan vien
        linkthemmoidoanvien.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("1", "gold", 128);
        linkquanlydoanvien.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("2", "gold", 128);
        linkdanhsachdoanvientrungthanh.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("3", "gold", 128);
        linkdanhsachdoanviendanhdu.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("4", "gold", 128);
        linkdanhsachgioithieudang.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("5", "gold", 128);
        linkdoanvienbixoa.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("6", "gold", 128);
        linkdoanviendubi.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("7", "gold", 128);
        linkdoanviencct.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("8", "gold", 128);
        linkdoanvienkhaitru.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("9", "gold", 128);
        linkdscanbodoan.NavigateUrl = PageURL.local + "DanhMuc/ChonDonViThemDoanVien.aspx?id=" + _ps.Encrypt("4", "gold", 128) + "&subid=" + _ps.Encrypt("10", "gold", 128);

        //Thong ke
        phuluc2a.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2a.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("1", "gold", 128);
        phuluc2b.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2b.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("2", "gold", 128);
        phuluc2c.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2c.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("3", "gold", 128);
        phuluc2d.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2d.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("4", "gold", 128);
        phuluc2e.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2e.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("5", "gold", 128);
        phuluc2g.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2g.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("6", "gold", 128);
        phuluc2h.NavigateUrl = PageURL.local + "ThongKe/PhuLuc2h.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("7", "gold", 128);
        thongketuybien.NavigateUrl = PageURL.local + "ThongKe/Thongketuybien.aspx?id=" + _ps.Encrypt("5", "gold", 128) + "&subid=" + _ps.Encrypt("8", "gold", 128);


        //phan dao tao
        linkchuongtrinhdaotao.NavigateUrl = PageURL.local + "DanhMuc/ChuongTrinhDaoTao.aspx?id=" + _ps.Encrypt("6", "gold", 128) + "&subid=" + _ps.Encrypt("1", "gold", 128);
        linkDangKyLopHoc.NavigateUrl = PageURL.local + "DanhMuc/DangKyLopHoc.aspx?id=" + _ps.Encrypt("6", "gold", 128) + "&subid=" + _ps.Encrypt("2", "gold", 128);
        //phan quyen he thong

        _dbDataContext _db = new _dbDataContext();
        int userid = _db.tblAcounts.Single(r => r.TenDangNhap.Trim() == this.Page.User.Identity.Name).ID;
        b = new HyperLink[Max];
        Menu();
        int lastroleid = _db.tblRoles.Max(r=>r.ID);
        var val = _db.tblUserInRoles.Where(r => r.UserID == userid && r.RolesID != lastroleid);
        int i = 0;
        foreach (var item in val)
        {
            b[i].Enabled = (bool)item.PhanQuyen;
            if (item.PhanQuyen == false)
            {
                b[i].ForeColor = System.Drawing.Color.DarkGray;
            }
            i++;
        }

        //khoa chuc nang quan ly co so doan khi tai khoan dang nhap la chi doan hoac chi doan co so
        string level = MemberShip_ASP.GetMaDonViFromUserName(this.Page.User.Identity.Name).Substring(0, 3);
        if (level == "CDC" || level == "CDD")
        {
            linkTaoMoiCSD.Enabled = false;
            linkCapNhatCSD.Enabled = false;
            linkTaoMoiCSD.ForeColor = System.Drawing.Color.DarkGray;
            linkCapNhatCSD.ForeColor = System.Drawing.Color.DarkGray;
        }
    }
}
